package com.student.service.impl;

import java.util.List;

import com.student.dao.StudentDao;
import com.student.dao.impl.StudentDaoImpl;
import com.student.entity.Student;
import com.student.service.StudentService;

public class StudentServiceImpl implements StudentService {
	private StudentDao studentDao = new StudentDaoImpl();
	
	@Override
	public List<Student> findList(Integer currentPage, Integer pageCount, String likename) {
		if(likename == null) {
			likename = "";
		}
		return studentDao.findList(currentPage, pageCount, likename);
	}
	
	@Override
	public Integer getTotalPage(Integer pageCount, String likename) {
		if(likename == null) {
			likename = "";
		}
		Integer total = studentDao.getTotal(likename);
		return (total - 1) / pageCount + 1;
	}
	

	@Override
	public void saveStudent(Student student) {
		if(student.isNewRecord()) {
			studentDao.insert(student);
		} else {
			studentDao.update(student);
		}
	}

	@Override
	public Student findStudentById(String sid) {
		return studentDao.findById(Integer.valueOf(sid));
	}

	@Override
	public void deleteStudent(String ids) {
		String[] temp = ids.split(",");
		int[] sids = new int[temp.length];
		for (int i = 0; i < temp.length; i++) {
			sids[i] = Integer.valueOf(temp[i]);
		}
		studentDao.batchDelete(sids);
	}

	
	
}
